#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
const ll N = 1e3 + 10;
ll dp[N][N][2];
ll a[N], b[N];
ll zhuan(ll x)
{
    vector<ll> jz;
    while (x)
    {
        jz.push_back(x % 2);
        x /= 2;
    }
    reverse(jz.begin(), jz.end());
    ll num = 1, re = 0;
    for (int i = 0; i < jz.size(); i++)
    {
        re += num * jz[i];
        num *= 2;
    }
    return re;
}
void solve()
{
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        ans += a[i];
        b[i] = zhuan(a[i]);
        dp[i][0][0] = ans;
    }
    // cout << zhuan(3) << endl;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            dp[i][j][0] = max(dp[i - 1][j][0], dp[i - 1][j][1]) + a[i];
            dp[i][j][1] = max(dp[i - 1][j - 1][0], dp[i - 1][j][1]) + b[i];
        }
    }

    for (int i = 1; i <= m; i++)
    {
        ans = max(ans, max(dp[n][i][0], dp[n][i][1]));
    }
    cout << ans;
}
int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
